package com.example.sampleworks.ui;


import java.util.ArrayList;
import java.util.List;

import com.example.sampleworks.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class ImageTextListViewActivity extends Activity implements OnItemClickListener {
	
	public static final String[] titles = new String[] { "Strawberry",
        "Banana", "Orange", "Mixed" };
	
	public static final String[] descriptions = new String[] {
		"It is an aggregate accessory fruit",
        "It is the largest herbaceous flowering plant", "Citrus Fruit",
        "Mixed Fruits"};

	public static final Integer[] images = { R.drawable.straw, R.drawable.ban, R.drawable.or, R.drawable.mix };
	
	ListView listView;
	List<RowItem> rowItems;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState) ;
		setContentView(R.layout.main);
			
		rowItems = new ArrayList<RowItem>();
		for (int i = 0; i <titles.length; i++) {
			RowItem item = new RowItem(images[i], titles[i], descriptions[i]);
			rowItems.add(item);
		}
		 
		listView = (ListView) findViewById(R.id.listView1);
		CustomListViewAdapter adapter = new CustomListViewAdapter(this,R.layout.list_view,rowItems);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		
		Toast toast = Toast.makeText(getApplicationContext(),
	            "Item " + (position + 1) + ": " + rowItems.get(position),
	            Toast.LENGTH_SHORT);
	        toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
	        toast.show();
		
	}
		
	}
	


